package com.cdl.singletontest;

/**
 * @author cdl
 * @date 2025/10/4
 */
public class Singleton2 {

    //双重检查锁定（Double-Checked Locking）
    //1.构造方法私有化
    private static Singleton2 instance;
    //2。声明一个本类对象
    private Singleton2() {}
    //3，下午外部提供歌曲的一年方法获取实例
    public static Singleton2 getInstance() {
        if (instance == null) {
            synchronized (Singleton2.class) {
                if (instance == null) {
                    instance = new Singleton2();
                }
            }
        }
        return instance;
    }
}

class Demo1{
    public static void main(String[] args) {
        Singleton2 s1 = Singleton2.getInstance();
        Singleton2 s2 = Singleton2.getInstance();
        System.out.println(s1 == s2);

    }
}
